<template>
	<view>
		<daya-footer-navbar menu_type="shangpin" />
		<u-sticky bgColor="#fff">
			<u-tabs :list="list" @click="onTabClick"></u-tabs>
		</u-sticky>
		<view class="goods">
			<view class="menu-wrapper">
				<scroll-view :scrollIntoView="toView" :scrollY="true" style="height: 82.5vh; padding-bottom: 10rpx">
					<view @tap="selectMenu" :class="'menu-item ' + (index == catalogSelect ? 'active' : '')"
						:data-id="item.id" :data-item-index="index" :id="'order' + index"
						v-for="(item, index) in dishes" :key="item.value">
						<!-- <view class="goods_border" :style="'background:' + color" v-if="index == catalogSelect"></view> -->

						<!-- <view class="text"> -->
						{{ item.type_name }}
						<!-- </view> -->
					</view>
				</scroll-view>
			</view>
			<scroll-view scrollY class="foods-wrapper"
				style="height: 82.5vh; padding-bottom: 10rpx">
				<!-- <view class="title" :style="'color:' + color">{{ dishes[catalogSelect].type_name }}</view> -->

				<view class="kong" v-if="dishes[catalogSelect].good.length == 0">
					<image
						src="https://ymqycc.oss-cn-chengdu.aliyuncs.com/ymqzho2o/static/ymq_canyino2o/pages/images/wushuju.png">
					</image>
					<view>此分类暂未添加商品</view>
				</view>

				<view :data-food="food" v-for="(food, index) in dishes[catalogSelect].good" :key="food.value">
					<view class="food-item">
						<view class="icon">
							<image :class="food.open ? 'bomb_show' : ''" :data-id="food.id" :id="food.id"
								mode="aspectFill" :src="food.logo" style="width: 130rpx; height: 130rpx">
								<view class="dndw" v-if="food.type == '1'">外卖商品</view>
								<view class="dndw" v-if="food.type == '2'">店内商品</view>
								<view class="dndw" v-if="food.type == '3'">店内+外卖</view>
							</image>
						</view>
						<view class="content">
							<view class="name elipsis">{{ food.name }}</view>
							<view class="extra" style="margin-top: 5rpx">
								<text class="count">月售{{ food.sales }}+</text>
								<text class="count">库存{{ food.inventory }}</text>
							</view>
							<view>
								<text class="sh_content6">外卖¥</text>
								<text class="sh_content6">{{ food.money }}</text>
								<text class="sh_content7" style="margin-left: 30rpx">店内¥</text>
								<text class="sh_content7">{{ food.dn_money }}</text>
							</view>
							<view class="cartControl-wrapper">
								<view class="cartControl"></view>
							</view>
						</view>
					</view>

					<view class="dbbj">
						<view @tap="bianj"  :data-cpid="food.id">
							<!-- <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/edit.png"></image> -->
							编辑
						</view>
						<view @tap="sccp"  :data-cpid="food.id">
							<!-- <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/delete.png"></image> -->
							删除
						</view>
						<view @tap="sjxj"  :data-cpid="food.id" data-shelves="1" v-if="food.is_show == '2'">
							上架</view>
						<view @tap="sjxj" :data-cpid="food.id" data-shelves="2" v-else>下架</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="footer">
			<view @tap="spfl" class="spfl" style="'background:#1E9CFC'">商品分类</view>
			<view @tap="tjsp" class="tjsp" style="'background:#1E9CFC'">添加商品</view>
		</view>
	</view>
</template>

<script>
	import cardlist from '@/ymq_canyino2o/dist/cardlist/index';
	import gettel from '@/ymq_canyino2o/dist/gettel/index';
	var app = getApp();
	var util = require('../../../utils/util.js');
	export default {
		components: {
			cardlist,
			gettel
		},
		data() {
			return {
				list: [{
						name: '全部',
						value: ''
					},
					{
						name: '已下架20',
						value: '2'
					},
					{
						name: '已售罄20',
						value: '3'
					},
				],
				catalogSelect: 0,
				height: '',
				toView: '',
				dishes: [],


				color: '',
				type_name: '',
				goods: [],

				food: {
					open: false,
					id: '',
					logo: '',
					type: '',
					name: '',
					inventory: '',
					sales: '',
					money: '',
					dn_money: '',
					is_show: ''
				},

				good: []
			};
		},
		onLoad: function(t) {
			app.globalData.setNavigationBarColor(this);
			var that = this;
			uni.getSystemInfo({
				success: function(t) {
					console.log(t.windowWidth);
					console.log(t.windowHeight);
					that.setData({
						height: (t.windowHeight / t.windowWidth) * 750 - 235
					});
				}
			});
		},
		onReady: function() {},
		onShow: function() {
			this.reLoad();
		},
		onHide: function() {},
		onUnload: function() {},
		onPullDownRefresh: function() {
			this.reLoad();
			uni.stopPullDownRefresh();
		},
		onReachBottom: function() {},
		methods: {
			onTabClick(item) {
				console.log(item.value);
				// this.dishes[this.catalogSelect].good.filter = 
			},
			spfl: function() {
				uni.navigateTo({
					url: 'spfl'
				});
			},

			tjsp: function() {
				uni.navigateTo({
					url: 'bjcp'
				});
			},

			selectMenu: function(t) {
				var e = t.currentTarget.dataset.itemIndex;
				this.setData({
					toView: 'order' + (Number(e) - 3),
					catalogSelect: t.currentTarget.dataset.itemIndex
				});
				console.log(this.catalogSelect);
				console.log(this.dishes[this.catalogSelect].good);
				console.log('order' + e.toString());
			},

			tjgg: function(t) {
				var e = t.currentTarget.dataset.cpid;
				console.log(e);
				uni.navigateTo({
					url: 'tjgg?cpid=' + e
				});
			},

			bianj: function(t) {
				var e = t.currentTarget.dataset.cpid;
				console.log(e);
				uni.navigateTo({
					url: 'bjcp?cpid=' + e
				});
			},

			sjxj: function(t) {
				var that = this;
				var o = t.currentTarget.dataset.cpid;
				var n = t.currentTarget.dataset.shelves;
				console.log(o, n);
				uni.showModal({
					title: '提示',
					content: '确认进行上下架操作吗？',
					success: function(t) {
						if (t.confirm) {
							console.log('用户点击确定');
							app.globalData.util.request({
								url: 'entry/wxapp/AddStoreDishes',
								cachetime: '0',
								data: {
									id: o,
									is_show: n
								},
								success: function(t) {
									console.log(t);
									if (1 == t.data) {
										uni.showToast({
											title: '操作成功',
											duration: 1000
										});
										setTimeout(function() {
											that.reLoad();
										}, 1000);
									}
								}
							});
						} else {
							if (t.cancel) {
								console.log('用户点击取消');
							}
						}
					}
				});
			},

			sccp: function(t) {
				var that = this;
				var o = t.currentTarget.dataset.cpid;
				console.log(o);
				uni.showModal({
					title: '提示',
					content: '确认删除此菜品吗？',
					success: function(t) {
						if (t.confirm) {
							console.log('用户点击确定');
							app.globalData.util.request({
								url: 'entry/wxapp/DelStoreGood',
								cachetime: '0',
								data: {
									id: o
								},
								success: function(t) {
									console.log(t);
									if (1 == t.data) {
										uni.showToast({
											title: '操作成功',
											duration: 1000
										});
										setTimeout(function() {
											that.reLoad();
										}, 1000);
									}
								}
							});
						} else {
							if (t.cancel) {
								console.log('用户点击取消');
							}
						}
					}
				});
			},

			reLoad: function() {
				var that = this;
				var t = uni.getStorageSync('sjdsjid');
				console.log("缓存:sjdsjid:", t);
				app.globalData.util.request({
					url: 'entry/wxapp/AppDishes',
					cachetime: '0',
					data: {
						store_id: t
					},
					success: (t) => {
						console.log(t.data);
						this.dishes = t.data
					}
				});
			}
		}
	};
</script>
<style scoped>
	@import './cplb.css';
</style>